package com.hsd.computer;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 模拟测试
 */
public class Customer {

    /**
     * 用户常规装配
     */
    @Test
    public void buyComputer001() {
        //配一台：内存 4G；磁盘：500G
        //创建内存条对象
        Memory4G memory4G = new Memory4G();
        //创建硬盘对象
        Disk500G disk500G = new Disk500G();
        //组装电脑
        Computer computer = new Computer(disk500G, memory4G);
        //显示当前电脑配置信息
        computer.computerInfo();
    }

    /**
     * 使用spring依赖注入进行装配
     */
    @Test
    public void buyComputer002() {
        //配一台：内存 4G；磁盘：500G
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        //获取在spring.xml中装配好的电脑
        Computer computer = (Computer) context.getBean("computer003");
        //显示当前电脑配置信息
        computer.computerInfo();
    }
}
